package org.mtmi.io;

import java.io.IOException;

import net.n3.nanoxml.IXMLElement;

import org.mtmi.ui.controls.Control;

/**
 * How to save/load a control.
 * This interface is retrieved using getAdapter( IControlIO.class ) on saved/loaded Control.
 */
public interface IControlIO 
{
	/**
	 * Implementors may save any useful data in current XML element.<br>
	 * Any link to other controls must be saved using control id
	 * @param c the control to write.
	 * @param w an XML writer to save data.
	 * @param sw Scene Writer should be used to get control's id's when writing references.
	 * @throws IOException
	 */
	public void writeControl( Control c, XMLWriter w, SceneWriter sw ) throws IOException;
	
	/**
	 * Implementors may read any useful data in current XML element.<br>
	 * Any link to other controls can be restored using control id (
	 * @param c the control to read data.
	 * @param r an XML reader to parse XML data.
	 * @param sr Scene Reader should be used to get control from id, to restore references.
	 * @throws ReaderError if any data is malformed or missed
	 */
	public void readControl( Control c, IXMLElement element, XMLReader r, SceneReader sr ) throws ReaderError;
}
